<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>FIRST</title>
		<style type="text/css">
			*{
				padding: 0;
				margin: 0;
			}
			.container{
				width: 100vw;
				height: 100vh;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		canvas{
			width: 400px;
			height: 400px;
			border: 10px solid #333333;
		}	
		
		</style>
	</head>
	<body>
		<div class="container">
		<canvas id="canvas" width="500" height="500"></canvas>
		</div>
	</body>
	<script>
		window.onload = function() {
			
			let oCanvas = document.getElementById('canvas');
		
			console.dir(oCanvas);
			
			let oPen=oCanvas.getContext("2d");
			
			//drawImage
//			let oImage = document.getElementById('img')
			
//			oPen.drawImage(oImage,0,0);
			//图片对象x，y；图片左上角对应的坐标
			
//			let oImage = new Image();
//			oImage.src="img/icon.png";
//			oImage.onload = function(){
//				oPen.drawImage(oImage,0,0,100,99);


                
//              oPen.drawImage(oImage,280,210,90,135,0,0,90,135);
//              //被截取图片的横坐标，被截取图片的纵坐标,被截取图片的宽度,被截取图片的高度,左上角坐标，y,w,h.
//              oPen.drawImage(oImage,125,275,50,70,90,0,50,70);
//              oPen.drawImage(oImage,223,285,40,70,130,0,40,70);
//              oPen.drawImage(oImage,254,100,60,100,170,0,60,100);
//              oPen.drawImage(oImage,200,150,50,80,230,0,50,80);


                //createPattern()
                //img,'repeat,repeat-x,repeat-y,no-repeat'
//              let myPattern = oPen.createPattern(oImage,'repeat-y');
//              oPen.fillStyle = myPattern;
//              oPen.fillRect(0,0,500,500);
                
//              let repeatCanvas = document.createElement('canvas');
//              repeatCanvas.width=30;
//              repeatCanvas.height=30;
//              let repeatPen = repeatCanvas.getContext("2d")
//              repeatPen.arc(15 ,15 ,15 ,0 ,Math.PI/180*360 ,true );
//              repeatPen.fillStyle="lavenderblush"
//              repeatPen.fill();
//              let myPattern = oPen.createPattern(repeatCanvas,'repeat');
//              oPen.fillStyle = myPattern;
//              oPen.fillRect(0,0,500,500);
                
                
//              oPen.arc(15 ,15 ,15 ,0 ,Math.PI/180*360 ,true );
//              oPen.fillStyle="blue"
//              oPen.fill();

                let oImage = new Image();
			    oImage.src="img/icon.png";
			    oImage.onload = function(){
				
               
                let myPattern = oPen.createPattern(oImage,'repeat');
                oPen.fillStyle = myPattern;
                oPen.font = "bolder 30px 黑体"
                oPen.fillText("我爱上课",100,100);
			}
		}	
	</script>
</html>
